#!/bin/bash
echo "====== 删除hadoop里的tmp ======"
ssh zhige01 "rm -rf /hadoop/hadoop-2.7.7/tmp"
ssh zhige02 "rm -rf /hadoop/hadoop-2.7.7/tmp"
ssh zhige03 "rm -rf /hadoop/hadoop-2.7.7/tmp"

echo "====== 启动 zhige01 的 zookeeper ======"
ssh zhige01 "/hadoop/zookeeper-3.4.13/bin/zkServer.sh start"
echo "====== 启动 zhige02 的 zookeeper ======"
ssh zhige02 "/hadoop/zookeeper-3.4.13/bin/zkServer.sh start"
echo "====== 启动 zhige03 的 zookeeper ======"
ssh zhige03 "/hadoop/zookeeper-3.4.13/bin/zkServer.sh start"

echo "====== 启动journalnode ======"
ssh zhige01 "/hadoop/hadoop-2.7.7/sbin/hadoop-daemon.sh start journalnode"
ssh zhige02 "/hadoop/hadoop-2.7.7/sbin/hadoop-daemon.sh start journalnode"
ssh zhige03 "/hadoop/hadoop-2.7.7/sbin/hadoop-daemon.sh start journalnode"

echo "====== 停顿15秒 ======"
sleep 15

echo "====== 格式化namenode ======"
hdfs namenode -format
scp -r /hadoop/hadoop-2.7.7/tmp/ root@zhige02:/hadoop/hadoop-2.7.7/
scp -r /hadoop/hadoop-2.7.7/tmp/ root@zhige03:/hadoop/hadoop-2.7.7/

echo "====== 格式化zkfc ======"
hdfs zkfc -formatZK

echo "====== 启动 HDFS ======"
/hadoop/hadoop-2.7.7/sbin/start-dfs.sh
echo "====== 启动资源管理器 YARN ======"
/hadoop/hadoop-2.7.7/sbin/start-yarn.sh
